<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2022-01-24
  Time: 14:13
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page  isELIgnored="false" %>
<html>
<head>
    <title>主页</title>
    <link rel="stylesheet" href="/js/layui/css/layui.css">
    <link rel="stylesheet" href="/css/login.css">
    <script src="/js/jquery-3.3.1.min.js"></script>
    <script src="/js/layui/layui.js"></script>
</head>
<body>
<%--    功能目录   --%>
<ul class="layui-nav">

    <li class="layui-nav-item">
        <a href="javascript:;">悦薇管理系统</a>
    </li>

    <li class="layui-nav-item">
<%--        <a href="javascript:;">权限管理</a>--%>
        <dd><a class="bts" path="user/users">用户管理</a></dd>
        <dl class="layui-nav-child"> <!-- 二级菜单 -->

           <%-- <dd><a  class="bts" path="menu/menuList">角色管理</a></dd>
            <dd><a  class="bts" path="role/roleList">菜单管理</a></dd>--%>
        </dl>
    </li>


    <li class="layui-nav-item layui-layout-right">
      <a  href=""><%--  <img src="${login_user.img}" class="layui-nav-img">--%><font color="red">${login_user.name}</font> <font>你好 个人中心</font> </a>
        <dl class="layui-nav-child">
            <dd><a href="javascript:;" id="updatePas">修改密码</a></dd>
            <dd><a href="/user/loginto.do">退出</a></dd>
        </dl>
    </li>
</ul>
<div id="neirong" class="layui-container">

</div>
<script type="text/html" id="upPass">
    <!--  修改密码   -->
    <form class="layui-form">



                <input type="hidden" name="id" value="${login_user.id}" placeholder="请输入" autocomplete="off" class="layui-input">



                <input type="hidden" name="name" value="${login_user.name}" placeholder="请输入" autocomplete="off" class="layui-input">

        <div class="layui-form-item">
            <label class="layui-form-label">原密码</label>
            <div class="layui-input-inline">
                <input type="password" name="password" placeholder="请输入原密码" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">新密码</label>
            <div class="layui-input-inline">
                <input type="password" name="password1" placeholder="请输入新密码" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <input type="button" class="layui-btn"  lay-submit lay-filter="upPas" value="修改" />
                <input type="reset" class="layui-btn layui-btn-primary" value="重置"/>
            </div>
        </div>
    </form>
</script>
<script>
    //注意：导航 依赖 element 模块，否则无法进行功能性操作
    layui.use('element', function(){
        var element = layui.element;
        var layer =layui.layer;
        var from=layui.form;
        $("#updatePas").on('click',function (){
            layer.open({
                type:1,
                title:"修改密码",
                area:"1000px",
                content:$("#upPass").html()
            });
            from.render();
        })
        from.on('submit(upPas)',function (res){
            if (res.field.password==""){
                layer.msg("原密码不能为空");
                return;
            }
            if (res.field.password1==""){
                layer.msg("新密码不能为空");
                return;
            }
            $.post({
                url:"/user/upPass.do",
                data:{"name":res.field.name,"id":res.field.id,"password":res.field.password,"password1":res.field.password1},

                success:function (rs) {
                   if (rs.data==2){
                        layer.msg("原密码错误");
                   }else {
                       layer.msg("网络异常"+rs.data);
                   }
                   if (rs.data==1){
                        layer.msg("修改成功，请重新登录，5秒后跳转登录页面",{time:5000},function(){
                            location.href="/login.jsp "
                        });
                    }
                }
            });
        })

        //绑定 跳出页面
        $(".bts").on("click",function (rs) {
            console.log(rs);
            // ajax返回的是个页面
            $.post({
                url:"/user/toCreateUser.do",
                data:{"page":rs.currentTarget.attributes.path.value},
                success:function (rs) {
                    $("#neirong").html(rs);
                }
            });

        });
    });
</script>
</body>
</html>
